package com.ghck.server.service.impl;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ghck.server.dao.UserInfoMapper;
import com.ghck.server.model.UserInfo;
import com.ghck.server.model.query.UserInfoQuery;
import com.ghck.server.service.UserInfoService;

/**
 * 用户信息表-用户扩展  <br>
 * t_user_info <br>
 * v1.0 2016-05-01
 */
 @Service
 @Transactional
 public class UserInfoServiceImpl implements UserInfoService {
	
	private static final Logger logger = LoggerFactory.getLogger(UserInfoServiceImpl.class);
	
	@Autowired
	private UserInfoMapper userInfoMapper;
	
	/**
 	*根据ID删除 用户信息表-用户扩展
 	*/
 	@Override
 	public Integer deleteUserInfoById(Integer id){
 		return userInfoMapper.deleteById(id);
 	}
 	
 	/**
 	*新增 用户信息表-用户扩展
 	*/
 	@Override
 	@Transactional
 	public Integer batchInsertUserInfo(List<? extends UserInfo> userInfos){
		Integer count = userInfoMapper.batchInsert(userInfos);
		return count;
 	}
 	/**
 	*新增 用户信息表-用户扩展
 	*/
 	@Override
 	@Transactional
 	public Integer insertUserInfo(UserInfo domain){
		Integer id = userInfoMapper.insert(domain);
		return id;
 	}

 	/**
 	*更新 用户信息表-用户扩展
 	*/
 	@Override
 	@Transactional
 	public Integer updateUserInfo(UserInfo domain){
		Integer count = userInfoMapper.update(domain);
		return count;
 	}
 	
 	/**
 	*根据ID查询 用户信息表-用户扩展
 	*/
 	public UserInfo findUserInfoById(Integer id){
 		UserInfo result = userInfoMapper.findById(id);
 		if(result!=null){
 			result.dealWith();
 		}
 		return result;
 	}

	/**
 	*通过query 查询 用户信息表-用户扩展
 	*/
	public List<UserInfo> findUserInfoByQuery(UserInfoQuery query){
		query.dealWith();
		List<UserInfo> result = userInfoMapper.findByQuery(query);
		if(CollectionUtils.isNotEmpty(result)) {
			for (UserInfo userInfo : result) {
				userInfo.dealWith();
			}
		}
		return result;
	}	
	
	/**
 	*通过query count总条数
 	*/
 	public Integer countUserInfoByQuery(UserInfoQuery query){
 		query.dealWith();
 		Integer result = userInfoMapper.countByQuery(query);
 		return result;
 	}
 	
 	/**
 	* 通过ids查询
 	*/
 	public List<UserInfo> findUserInfoByIds(List<Integer> ids){
 		List<UserInfo> result = userInfoMapper.findByIds(ids);
		if(CollectionUtils.isNotEmpty(result)) {
			for (UserInfo userInfo : result) {
				userInfo.dealWith();
			}
		}
		return result;
 	}
 	
}	